Editor.ResourceConnectable = function () {
	var draggerConnector;
	var impl;
	var resource;
	var inProperties;
	var superType;
	var type;
	return {
	  init: function (u) {
	    impl = this;
	    resource = new Editor.Resource();
	    resource.init(u,this, superType);
	    draggerConnector = new Editor.DraggerConnector();
	    draggerConnector.init(resource);
	    inProperties = new Array();
	    type = 'resource';
	  },
	  setBlank: function () {
	    type = 'blank';
	  },
	  unsetBlank: function () {
	    type = 'resource';
	  },
	  addInProperties: function (propUuid) {
	    inProperties.push(propUuid);
	  },
	  removeInProperties: function (propUuid) {
	    var deleted = false;
	    for(var i=0; i<inProperties.length; i++) {
	      if (!deleted && inProperties[i] == propUuid) {
	        inProperties.splice(i,1);
	        deleted = true;
	      }
	    }
	  },
	  getTypeClass: function () {
	    return type;
	  },
	  getInfo: function () {
	    var str = '';
	    if (Editor.CONFIG.DEBUG) {
      	str = 'ResourceConnectable:\n';
      	str += '\n';
			}
      str += resource.getInfo();
			return str;
		},
		getNamespace: function () {
			return resource.getNamespace();
		},
		setNamespace: function (n) {
			resource.setNamespace(n);
		},
		getName: function () {
			return resource.getName();
		},
		setName: function (n) {
			resource.setName(n);
		},
		getText: function () {
			var t = resource.getText();
			return t;
		},
		_remove: function () {
      resource._remove();
			draggerConnector.remove();
		},
		remove: function () {
			var arrProperties = Array();
			for (var i=0;i<inProperties.length;i++) {
				var s = Editor.STATE.SHAPES.get(inProperties[i]);
				if (!s.isDeleted()) {
					arrProperties.push(inProperties[i]);
				}
			}
      var cmd = new JS.Command({
        execute: function () {
      		resource.remove();
					draggerConnector.remove();
					for(var i=0;i<arrProperties.length;i++) {	
						var s = Editor.STATE.SHAPES.get(arrProperties[i]);
						if (!s.isDeleted()) {
							s._remove();
						}
					}
        },
        undo: function () {
          impl.draw();
					for(var i=0;i<arrProperties.length;i++) {
						var s = Editor.STATE.SHAPES.get(arrProperties[i]);
						if (s.isDeleted()) {
							s.draw();
						}
					}
        },
        stack: Editor.STATE.CMDSTACK
      });
      cmd.name = 'remove resource';
      cmd.execute();
		},
		draw: function () {
			resource.draw(impl);
			draggerConnector.draw();
			draggerConnector.redraw();
		},
		toFront: function () {
			resource.toFront();
			draggerConnector.toFront();
		},
		toFrontProperties: function () {
			for (var i=0;i<inProperties.length;i++) {
				var p = Editor.STATE.SHAPES.get(inProperties[i]);
				if (!p.isDeleted()) {
					p.toFrontArrowPoint();
				}
			}
		},
		moveTo: function (x, y) {
			resource.moveTo(x, y);
            this.updateLines();
		},
		translate: function (dx, dy) {
			resource._translate(dx,dy);
			draggerConnector.translate(dx, dy);
		},
		_translate: function (dx, dy) {
			resource._translate(dx,dy);
			draggerConnector.translate(dx, dy);
		},
		_resize: function (dw, dh) {
			resource._resize(dw, dh);
			draggerConnector.redraw();
			draggerConnector.toFront();
			this.updateLines();
		},
		resize: function (dw, dh) {
			resource.resize(dw, dh);
			draggerConnector.redraw();
			draggerConnector.toFront();
			this.updateLines();
		},
		updateLines: function () {
			Editor.STATE.SHAPES.forEach(function(pair) {
				if (!pair.value.isDeleted()) {
					var s = pair.value;
					if (s.getTypeClass() == "property" && (s.getUuidEnd() == resource.getUuid() || s.getUuidIni() == resource.getUuid())) {
						s.drawLines();
					}
				}
			});
		},
    getTextAttr: function () {
      return Editor.CONFIG.SHAPE_ATTR_TEXT;
    },
		figure: function () {
			return resource.figure();
		},
		getShapeAttr: function () {
			return resource.getShapeAttr();
		},
		getUuid: function () {
			return resource.getUuid();
		},
		isDeleted: function () {
			return resource.isDeleted();
		},
		getX: function () {
			return resource.getX();
		},
		getY: function () {
			return resource.getY();
		},
		getWidth: function () {
			return resource.getWidth();
		},
		getHeight: function () {
			return resource.getHeight();
		},
		toString: function () {
			return resource.toString();
		},
		select: function () {
			resource.select();
		},
		unselect: function () {
			Editor.Util.unselect(resource);
			resource.unselect();	
		},
		frameResize: function () {
			return resource.frameResize();
		},
		saveIni: function (e) {
			resource.saveIni(e);
		},
		getIniPosx: function () {
			return resource.getIniPosx();
		},
		getIniPosy: function () {
			return resource.getIniPosy();
		},
		mousedown: function (e) {
			if (!Editor.Util.isDragging()) {
				resource.mousedown(e);
			}
		},
		mouseover: function () {
			if (!Editor.Util.isDragging()) {
				resource.mouseover();
				draggerConnector.mouseover();
			}
		},
		mouseout: function () {
			if (!Editor.Util.isDragging()) {
				resource.mouseout();
				draggerConnector.mouseout();
			}
		},
		click: function () {
			if (!Editor.Util.isDragging()) {
				resource.click();
				draggerConnector.toFront();
				impl.toFrontProperties();
			}
		},
		updateText: function () {
			resource.updateText();
		},
		getMinWidth: function () {
			return resource.getMinWidth();
		},
		getMinHeight: function () {
			return resource.getMinHeight();
		},
		showEdit: function () {
			resource.showEdit();
		},
		getDeckEdit: function () {
			return resource.getDeckEdit();
		},
		getDraggerConnector: function () {
			return draggerConnector;
		},
		onmouseup: function () {
			this.updateLines();
		},
		getInProperties: function () {
			return inProperties;
		},
		toObject: function () {
			return {
				'type': 'resource',
				'rdftype': superType,
				'resource': resource.toObject()
			}
		},
		setSuperType: function(t){
		  superType=t;
		  resource.setSuperType(t);
		},
		getSuperType: function(){
		  return superType;
		}
	}
}
